package com.zoe.springcloud;/*
 *@date 2019/12/11 0011
 */

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author xiejiarong
 */
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
//以上三个注解也可以使用 @SpringCloudApplication
public class RibbonConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(RibbonConsumerApplication.class,args);
    }

  /**
   *注册一个restTemplate用来调用服务
   * */
  //开启负载均衡功能
   @LoadBalanced
   @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
    * 自定义负载均衡策略（随机）
     */
    @Bean
    public IRule myRule(){
       return new RoundRobinRule();
    }
}
